﻿using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Data;
namespace WPFExcelReport
{
    public partial class TVR04
    {

        public TVR04()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVRKOPF();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, System.EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                KEY = "";
                KUNDNR = "";
                ZAHLBED = "";
                TXTISIND = "";
            }
            else
            {
                KEY = dwMaster["VRKRENR"].ToString();
                KUNDNR = dwMaster["VRKKUNDNR"].ToString();
                ZAHLBED = dwMaster["VRKZAHLBED"].ToString();
                TXTISIND = dwMaster["VRKRENR"].ToString().PadRight(60);
            }
        }
        public override void OnVKKChg(string vkk)
        {
            base.OnVKKChg(vkk);
            if (!IsAuto)
                return;
            if (vkk.Length < 9)
                return;
            if (TBMain.Rows.Count == 0)
            {
                dwData = TBMain.NewRow();
                TMV.SetUpNewRow(ref dwData);
                string _LFD = VSDDAT.SD22.GETNEXT("0022", "VR", "VRRENR", 1);
                dwData["VRKMANDANT"] = app.Mandant;
                dwData["VRKRENR"] = Helpers.Helper.Right("00000000" + _LFD, 8); ;
                dwData["VRKVERBNR"] = vkk.Substring(1, 8);
                dwData["VRKREART"] = "RE";
                dwData["VRKZESSION"] = "K";
                string auftyp = vkk.Substring(0, 1);
                switch (auftyp)
                {
                    case "B":
                        dwData["VRKREART"] = "EK";
                        dwData["VRKZESSION"] = "B";
                        break;
                     case "K":
                        dwData["VRKREART"] = "RE";
                        dwData["VRKZESSION"] = "K";
                        break; 
                } 
                TMV.Insert(dwData);
            }
            vwMaster.View.MoveCurrentToFirst();
        }

        public override void OnADSLChg(string _adsl)
        {
            base.OnADSLChg(_adsl); 
        }

        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            base.NewCommand(sender, e);
            //MessageBox.Show("发票必须基于销售单开具，请设定合适的销售单类型，并从销售单程序进入发票管理");
        }
    }
}